package com.sacc.controller;

import com.google.gson.Gson;
import com.power.common.model.CommonResult;
import com.sacc.pojo.Article;
import com.sacc.pojo.ProductInfoAll;
import com.sacc.service.ArticleService;
import com.sacc.util.OssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author 滚~韬
 * @date 2022/4/19 16:28
 */
@RestController
@RequestMapping("/news/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @Autowired
    private OssUtil ossUtil;
    @GetMapping("/getlist")
    public List<Article> getArticleList(@RequestParam Integer count) throws IOException {
        return articleService.GetArticleList(count);
    }
    @GetMapping("/get")
    public Article getArticle(@RequestParam Integer id) throws IOException {
        return articleService.GetArticle(id);
    }
    @PostMapping("/delete")
    public CommonResult deleteArticle(@RequestParam Integer id){
        return articleService.DeleteArticle(id);
    }
    @PostMapping("/add")
    public CommonResult addArticle(String article, MultipartFile file,String content){
        Gson gson = new Gson();
        Article articleObject = gson.fromJson(article, Article.class);
        articleObject.setContent(content);
        return articleService.AddArticle(articleObject,file);
    }

}
